
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.集合架构 · 计算机 ,java , 大数据 基础知识体系</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="hzh">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="2.HashMap源码分析.html" />
    
    
    <link rel="prev" href="../../多线程/10面试题二.html" />
    

    
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">操作系统</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../操作系统/1.基本概述.html">
            
                <a href="../../操作系统/1.基本概述.html">
            
                    
                    1.操作系统基本概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../操作系统/2.进程管理之进程与线程.html">
            
                <a href="../../操作系统/2.进程管理之进程与线程.html">
            
                    
                    2.进程管理之进程与线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../操作系统/3.进程管理之处理机调度.html">
            
                <a href="../../操作系统/3.进程管理之处理机调度.html">
            
                    
                    3.进程管理之处理机调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../操作系统/4.进程管理之进程同步.html">
            
                <a href="../../操作系统/4.进程管理之进程同步.html">
            
                    
                    4.进程管理之进程同步
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../../操作系统/5.内存管理之基本概念.html">
            
                <a href="../../操作系统/5.内存管理之基本概念.html">
            
                    
                    5.内存管理之基本概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../../操作系统/6.内存管理之虚拟内存.html">
            
                <a href="../../操作系统/6.内存管理之虚拟内存.html">
            
                    
                    6.内存管理之虚拟内存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../../操作系统/7.IO设备管理之基本概念.html">
            
                <a href="../../操作系统/7.IO设备管理之基本概念.html">
            
                    
                    7.IO设备管理之基本概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../../操作系统/8.面试题总结一.html">
            
                <a href="../../操作系统/8.面试题总结一.html">
            
                    
                    8.面试题总结一
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">计算机网络篇</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../../计算机网络/1.计算机网络入门基础概念.html">
            
                <a href="../../计算机网络/1.计算机网络入门基础概念.html">
            
                    
                    1.计算机网络入门文章(必读)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../../计算机网络/2.计算机网络通信基础.html">
            
                <a href="../../计算机网络/2.计算机网络通信基础.html">
            
                    
                    2.计算机网络通信入门文章(必读)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../../计算机网络/3.数据链路层.html">
            
                <a href="../../计算机网络/3.数据链路层.html">
            
                    
                    3.数据链路层
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../../计算机网络/4.网络层1.html">
            
                <a href="../../计算机网络/4.网络层1.html">
            
                    
                    4.网络层(一)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../../计算机网络/5.网络层2.html">
            
                <a href="../../计算机网络/5.网络层2.html">
            
                    
                    5.网络层(二)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../../计算机网络/6.传输层.html">
            
                <a href="../../计算机网络/6.传输层.html">
            
                    
                    6.传输层
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../../计算机网络/7.应用层.html">
            
                <a href="../../计算机网络/7.应用层.html">
            
                    
                    7.应用层(⭐)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="../../计算机网络/10.HTTP相关协议.html">
            
                <a href="../../计算机网络/10.HTTP相关协议.html">
            
                    
                    8.HTTP相关及发展
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" >
            
                <span>
            
                    
                    9.websocket
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="../../计算机网络/9.面试题二.html">
            
                <a href="../../计算机网络/9.面试题二.html">
            
                    
                    面试题总结一
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">数据结构篇</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../../数据结构/1.图论.html">
            
                <a href="../../数据结构/1.图论.html">
            
                    
                    1.图论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../../数据结构/2.图论例题.html">
            
                <a href="../../数据结构/2.图论例题.html">
            
                    
                    2.图论例题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../../数据结构/3.散列表.html">
            
                <a href="../../数据结构/3.散列表.html">
            
                    
                    3.散列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../../数据结构/4.排序算法.html">
            
                <a href="../../数据结构/4.排序算法.html">
            
                    
                    4.排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../../数据结构/5.排序列题.html">
            
                <a href="../../数据结构/5.排序列题.html">
            
                    
                    5.排序算法例题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../../数据结构/6.树论.html">
            
                <a href="../../数据结构/6.树论.html">
            
                    
                    6.树论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../../数据结构/7.树论例题.html">
            
                <a href="../../数据结构/7.树论例题.html">
            
                    
                    7.树论例题.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="../../数据结构/9.模板.html">
            
                <a href="../../数据结构/9.模板.html">
            
                    
                    数据结构模板
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">算法篇</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../算法/leetCode周赛题解.html">
            
                <a href="../../算法/leetCode周赛题解.html">
            
                    
                    leetCode周赛记录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../../算法/1.时间复杂度.html">
            
                <a href="../../算法/1.时间复杂度.html">
            
                    
                    1.时间复杂度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../../算法/2.深度优先搜索.html">
            
                <a href="../../算法/2.深度优先搜索.html">
            
                    
                    2.深度优先搜索算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../../算法/2.深度优先搜索题目集.html">
            
                <a href="../../算法/2.深度优先搜索题目集.html">
            
                    
                    2.深搜题目集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../../算法/3.广度优先搜索.html">
            
                <a href="../../算法/3.广度优先搜索.html">
            
                    
                    3.广度优先搜索算法
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">JVM篇</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../../jvm/1.jvm内存结构.html">
            
                <a href="../../jvm/1.jvm内存结构.html">
            
                    
                    1.jvm内存结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../../jvm/2.HotSpot虚拟机对象探秘.html">
            
                <a href="../../jvm/2.HotSpot虚拟机对象探秘.html">
            
                    
                    2.HotSpot虚拟机对象探秘.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../../jvm/3.对象存亡与垃圾收集算法.html">
            
                <a href="../../jvm/3.对象存亡与垃圾收集算法.html">
            
                    
                    3.对象存亡与垃圾收集算法.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../../jvm/4.HotSpot的算法细节与垃圾收集器.html">
            
                <a href="../../jvm/4.HotSpot的算法细节与垃圾收集器.html">
            
                    
                    4.HotSpot的算法细节与垃圾收集器.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../../jvm/5.内存分配与回收策略.html">
            
                <a href="../../jvm/5.内存分配与回收策略.html">
            
                    
                    5.内存分配与回收策略.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../../jvm/6.类文件结构.html">
            
                <a href="../../jvm/6.类文件结构.html">
            
                    
                    6.类文件结构.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="../../jvm/7.类加载机制.html">
            
                <a href="../../jvm/7.类加载机制.html">
            
                    
                    7.类加载机制.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.8" data-path="../../jvm/8.jvm逃逸分析.html">
            
                <a href="../../jvm/8.jvm逃逸分析.html">
            
                    
                    8.逃逸分析技术
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">多线程篇</li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../../多线程/basic/0.多线程路线图.html">
            
                <a href="../../多线程/basic/0.多线程路线图.html">
            
                    
                    1.多线程学习路线图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../../多线程/basic/0.java内存模型与线程.html">
            
                <a href="../../多线程/basic/0.java内存模型与线程.html">
            
                    
                    2.java内存模型与线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="../../多线程/3.并行程序基础.html">
            
                <a href="../../多线程/3.并行程序基础.html">
            
                    
                    2.并行程序基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="../../多线程/basic/0.jhappenBefore与jvm指令重排.html">
            
                <a href="../../多线程/basic/0.jhappenBefore与jvm指令重排.html">
            
                    
                    3.happenBefore与jvm指令重排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="../../多线程/basic/1.synchronized与volatile.html">
            
                <a href="../../多线程/basic/1.synchronized与volatile.html">
            
                    
                    4.synchronized与volatile.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="../../多线程/basic/2.ThreadLocal.html">
            
                <a href="../../多线程/basic/2.ThreadLocal.html">
            
                    
                    5.ThreadLocal.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="../../多线程/cas/1.乐观锁与悲观锁.html">
            
                <a href="../../多线程/cas/1.乐观锁与悲观锁.html">
            
                    
                    6.乐观锁与悲观锁.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="../../多线程/cas/2.CAS与atomic类.html">
            
                <a href="../../多线程/cas/2.CAS与atomic类.html">
            
                    
                    7.CAS与atomic类.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.9" data-path="../../多线程/aqs/1.AQS.html">
            
                <a href="../../多线程/aqs/1.AQS.html">
            
                    
                    8.AQS.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.10" data-path="../../多线程/aqs/2.基于AQS的并发工具.html">
            
                <a href="../../多线程/aqs/2.基于AQS的并发工具.html">
            
                    
                    9.基于AQS的并发工具.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.11" data-path="../../多线程/blockingQueue/1.阻塞队列.html">
            
                <a href="../../多线程/blockingQueue/1.阻塞队列.html">
            
                    
                    10.阻塞队列.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.12" data-path="../../多线程/pond/1.线程池与底层原理.html">
            
                <a href="../../多线程/pond/1.线程池与底层原理.html">
            
                    
                    11.线程池与底层原理.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.13" data-path="../../多线程/10面试题一.html">
            
                <a href="../../多线程/10面试题一.html">
            
                    
                    12.面试题一
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.14" data-path="../../多线程/10面试题二.html">
            
                <a href="../../多线程/10面试题二.html">
            
                    
                    13.面试题二.md
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">java集合篇</li>
        
        
    
        <li class="chapter active" data-level="7.1" data-path="1.java集合.html">
            
                <a href="1.java集合.html">
            
                    
                    1.集合架构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="2.HashMap源码分析.html">
            
                <a href="2.HashMap源码分析.html">
            
                    
                    2.hashMap底层原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="3.ConcurrentHashMap分析.html">
            
                <a href="3.ConcurrentHashMap分析.html">
            
                    
                    3.ConcurrentHashMap分析
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">设计模式篇</li>
        
        
    
        <li class="chapter " data-level="8.1" >
            
                <span>
            
                    
                    1.创造型模式
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="../../设计模式/factory/三种工厂模式介绍.html">
            
                <a href="../../设计模式/factory/三种工厂模式介绍.html">
            
                    
                    三种工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="../../设计模式/factory/实战工厂模式.html">
            
                <a href="../../设计模式/factory/实战工厂模式.html">
            
                    
                    实战工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="../../设计模式/factory/实战抽象工厂模式.html">
            
                <a href="../../设计模式/factory/实战抽象工厂模式.html">
            
                    
                    实战抽象工厂模式
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">mysql篇</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../../数据库/mysql/1.b树b+树的底层原理.html">
            
                <a href="../../数据库/mysql/1.b树b+树的底层原理.html">
            
                    
                    1.mysql索引基础之b树与b+树⭐⭐
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="../../数据库/mysql/2.mysql索引.html">
            
                <a href="../../数据库/mysql/2.mysql索引.html">
            
                    
                    2.mysql索引及优化⭐⭐⭐⭐
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="../../数据库/mysql/3.mysql存储引擎.html">
            
                <a href="../../数据库/mysql/3.mysql存储引擎.html">
            
                    
                    3.mysql存储引擎.md
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.4" data-path="../../数据库/mysql/4.多版本并发控制之mvcc原理.html">
            
                <a href="../../数据库/mysql/4.多版本并发控制之mvcc原理.html">
            
                    
                    4.多版本并发控制之mvcc原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.5" data-path="../../数据库/mysql/4.mysql事务.html">
            
                <a href="../../数据库/mysql/4.mysql事务.html">
            
                    
                    5.mysql事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.6" data-path="../../数据库/mysql/5.mysql锁机制.html">
            
                <a href="../../数据库/mysql/5.mysql锁机制.html">
            
                    
                    6.mysql的锁机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.7" data-path="../../数据库/mysql/6.mysql面试题一.html">
            
                <a href="../../数据库/mysql/6.mysql面试题一.html">
            
                    
                    7.mysql面试题一
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">高并发中间件篇</li>
        
        
    

    
        
        <li class="header">架构理论篇</li>
        
        
    
        <li class="chapter " data-level="11.1" data-path="../../架构/0.架构演进.html">
            
                <a href="../../架构/0.架构演进.html">
            
                    
                    1.架构演进
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="11.2" data-path="../../架构/0.微服务架构与soa架构.html">
            
                <a href="../../架构/0.微服务架构与soa架构.html">
            
                    
                    2.微服务架构与soa架构
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">高可用系统篇</li>
        
        
    
        <li class="chapter " data-level="12.1" data-path="../../高可用架构/1.限流.html">
            
                <a href="../../高可用架构/1.限流.html">
            
                    
                    1.系统限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="../../高可用系统/2.服务熔断.html">
            
                <a href="../../高可用系统/2.服务熔断.html">
            
                    
                    2.服务熔断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="12.3" data-path="../../高可用系统/3.服务降级.html">
            
                <a href="../../高可用系统/3.服务降级.html">
            
                    
                    3.服务降级
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">spring-cloud 微服务篇</li>
        
        
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >1.集合架构</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><ul><li><span class="title-icon "></span><a href="#&#x6982;&#x8FF0;"><b></b>&#x6982;&#x8FF0;:</a></li><li><span class="title-icon "></span><a href="#&#x6CE8;&#x610F;"><b></b>&#x6CE8;&#x610F;:</a></li><li><span class="title-icon "></span><a href="#&#x603B;&#x7ED3;"><b></b>&#x603B;&#x7ED3;:</a></li><ul><li><span class="title-icon "></span><a href="#connection&#x63A5;&#x53E3;"><b></b>Connection&#x63A5;&#x53E3;:</a></li><li><span class="title-icon "></span><a href="#map&#x63A5;&#x53E3;"><b></b>Map&#x63A5;&#x53E3;:</a></li></ul><li><span class="title-icon "></span><a href="#&#x91CD;&#x70B9;&#x95EE;&#x9898;&#x91CD;&#x70B9;&#x5206;&#x6790;"><b></b>&#x91CD;&#x70B9;&#x95EE;&#x9898;&#x91CD;&#x70B9;&#x5206;&#x6790;:</a></li><ul><li><span class="title-icon "></span><a href="#&#x4E00;treeset-linkedhashset-and-hashset-&#x7684;&#x533A;&#x522B;"><b></b>(&#x4E00;).TreeSet, LinkedHashSet and HashSet &#x7684;&#x533A;&#x522B;</a></li><li><span class="title-icon "></span><a href="#&#x4E8C;treeset&#x7684;&#x4E24;&#x79CD;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;"><b></b>(&#x4E8C;).TreeSet&#x7684;&#x4E24;&#x79CD;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;</a></li><li><span class="title-icon "></span><a href="#&#x4E09;-&#x6027;&#x80FD;&#x6D4B;&#x8BD5;"><b></b>(&#x4E09;). &#x6027;&#x80FD;&#x6D4B;&#x8BD5;</a></li></ul></ul></ul></div><a href="#" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h2 id="&#x6982;&#x8FF0;"><a name="&#x6982;&#x8FF0;" class="anchor-navigation-ex-anchor" href="#&#x6982;&#x8FF0;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x6982;&#x8FF0;" class="plugin-anchor" href="#&#x6982;&#x8FF0;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6982;&#x8FF0;:</h2>
<ul>
<li>List , Set, Map&#x90FD;&#x662F;&#x63A5;&#x53E3;&#xFF0C;&#x524D;&#x4E24;&#x4E2A;&#x7EE7;&#x627F;&#x81F3;Collection&#x63A5;&#x53E3;&#xFF0C;Map&#x4E3A;&#x72EC;&#x7ACB;&#x63A5;&#x53E3;</li>
<li>Set&#x4E0B;&#x6709;HashSet&#xFF0C;LinkedHashSet&#xFF0C;TreeSet</li>
<li>List&#x4E0B;&#x6709;ArrayList&#xFF0C;Vector&#xFF0C;LinkedList</li>
<li>Map&#x4E0B;&#x6709;Hashtable&#xFF0C;LinkedHashMap&#xFF0C;HashMap&#xFF0C;TreeMap</li>
<li>Collection&#x63A5;&#x53E3;&#x4E0B;&#x8FD8;&#x6709;&#x4E2A;Queue&#x63A5;&#x53E3;&#xFF0C;&#x6709;PriorityQueue&#x7C7B;</li>
</ul>
<p><img src="https://gitee.com/zisuu/picture/raw/master/img/20201221155058.jpeg" alt="img"></p>
<p><img src="https://gitee.com/zisuu/picture/raw/master/img/20201221155030.png" alt="image-20201221155030611"></p>
<h2 id="&#x6CE8;&#x610F;"><a name="&#x6CE8;&#x610F;" class="anchor-navigation-ex-anchor" href="#&#x6CE8;&#x610F;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x6CE8;&#x610F;" class="plugin-anchor" href="#&#x6CE8;&#x610F;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6CE8;&#x610F;:</h2>
<ul>
<li>Queue&#x63A5;&#x53E3;&#x4E0E;List&#x3001;Set&#x540C;&#x4E00;&#x7EA7;&#x522B;&#xFF0C;&#x90FD;&#x662F;&#x7EE7;&#x627F;&#x4E86;Collection&#x63A5;&#x53E3;&#x3002;
&#x770B;&#x56FE;&#x4F60;&#x4F1A;&#x53D1;&#x73B0;,LinkedList&#x65E2;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;Queue&#x63A5;&#x53E3;,&#x4E5F;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;List&#x63A5;&#x53E3;.&#x53EA;&#x4E0D;&#x8FC7;&#x5462;, LinkedList&#x5B9E;&#x73B0;&#x4E86;Queue&#x63A5;&#x53E3;&#x3002;Queue&#x63A5;&#x53E3;&#x7A84;&#x5316;&#x4E86;&#x5BF9;LinkedList&#x7684;&#x65B9;&#x6CD5;&#x7684;&#x8BBF;&#x95EE;&#x6743;&#x9650;&#xFF08;&#x5373;&#x5728;&#x65B9;&#x6CD5;&#x4E2D;&#x7684;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x5982;&#x679C;&#x662F;Queue&#x65F6;&#xFF0C;&#x5C31;&#x5B8C;&#x5168;&#x53EA;&#x80FD;&#x8BBF;&#x95EE;Queue&#x63A5;&#x53E3;&#x6240;&#x5B9A;&#x4E49;&#x7684;&#x65B9;&#x6CD5; &#x4E86;&#xFF0C;&#x800C;&#x4E0D;&#x80FD;&#x76F4;&#x63A5;&#x8BBF;&#x95EE; LinkedList&#x7684;&#x975E;Queue&#x7684;&#x65B9;&#x6CD5;&#xFF09;&#xFF0C;&#x4EE5;&#x4F7F;&#x5F97;&#x53EA;&#x6709;&#x6070;&#x5F53;&#x7684;&#x65B9;&#x6CD5;&#x624D;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x3002;</li>
<li>SortedSet&#x662F;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x5B83;&#x91CC;&#x9762;&#x7684;&#xFF08;&#x53EA;&#x6709;TreeSet&#x8FD9;&#x4E00;&#x4E2A;&#x5B9E;&#x73B0;&#x53EF;&#x7528;&#xFF09;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x4E00;&#x5B9A;&#x662F;&#x6709;&#x5E8F;&#x7684;&#x3002;</li>
</ul>
<h2 id="&#x603B;&#x7ED3;"><a name="&#x603B;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x603B;&#x7ED3;" class="plugin-anchor" href="#&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x603B;&#x7ED3;:</h2>
<h3 id="connection&#x63A5;&#x53E3;"><a name="connection&#x63A5;&#x53E3;" class="anchor-navigation-ex-anchor" href="#connection&#x63A5;&#x53E3;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="connection&#x63A5;&#x53E3;" class="plugin-anchor" href="#connection&#x63A5;&#x53E3;"><i class="fa fa-link" aria-hidden="true"></i></a>Connection&#x63A5;&#x53E3;:</h3>
<p>&#x2014; <strong>List &#x6709;&#x5E8F;,&#x53EF;&#x91CD;&#x590D;</strong></p>
<ul>
<li>ArrayList
<strong>&#x4F18;&#x70B9;:</strong> &#x5E95;&#x5C42;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x67E5;&#x8BE2;&#x5FEB;&#xFF0C;&#x589E;&#x5220;&#x6162;&#x3002;
<strong>&#x7F3A;&#x70B9;:</strong> &#x7EBF;&#x7A0B;&#x4E0D;&#x5B89;&#x5168;&#xFF0C;&#x6548;&#x7387;&#x9AD8;</li>
<li>Vector
<strong>&#x4F18;&#x70B9;:</strong> &#x5E95;&#x5C42;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x662F;&#x6570;&#x7EC4;&#xFF0C;&#x67E5;&#x8BE2;&#x5FEB;&#xFF0C;&#x589E;&#x5220;&#x6162;&#x3002;
<strong>&#x7F3A;&#x70B9;:</strong> &#x7EBF;&#x7A0B;&#x5B89;&#x5168;&#xFF0C;&#x6548;&#x7387;&#x4F4E;</li>
<li>LinkedList
<strong>&#x4F18;&#x70B9;:</strong> &#x5E95;&#x5C42;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x662F;&#x94FE;&#x8868;&#xFF0C;&#x67E5;&#x8BE2;&#x6162;&#xFF0C;&#x589E;&#x5220;&#x5FEB;&#x3002;
<strong>&#x7F3A;&#x70B9;:</strong> &#x7EBF;&#x7A0B;&#x4E0D;&#x5B89;&#x5168;&#xFF0C;&#x6548;&#x7387;&#x9AD8;</li>
</ul>
<p>&#x2014;<strong>Set &#x65E0;&#x5E8F;,&#x552F;&#x4E00;</strong></p>
<ul>
<li><p>HashSet
&#x5E95;&#x5C42;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x662F;&#x54C8;&#x5E0C;&#x8868;&#x3002;(&#x65E0;&#x5E8F;,&#x552F;&#x4E00;)
&#x5982;&#x4F55;&#x6765;&#x4FDD;&#x8BC1;&#x5143;&#x7D20;&#x552F;&#x4E00;&#x6027;?
1.&#x4F9D;&#x8D56;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#xFF1A;hashCode()&#x548C;equals()</p>
<p>equals()&#x8FD4;&#x56DE;True,hashCode&#x8FD4;&#x56DE;&#x76F8;&#x540C;</p>
</li>
<li><p>LinkedHashSet
&#x5E95;&#x5C42;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x662F;&#x94FE;&#x8868;&#x548C;&#x54C8;&#x5E0C;&#x8868;&#x3002;(FIFO&#x63D2;&#x5165;&#x6709;&#x5E8F;,&#x552F;&#x4E00;)
1.&#x7531;&#x94FE;&#x8868;&#x4FDD;&#x8BC1;&#x5143;&#x7D20;&#x6709;&#x5E8F;
2.&#x7531;&#x54C8;&#x5E0C;&#x8868;&#x4FDD;&#x8BC1;&#x5143;&#x7D20;&#x552F;&#x4E00;</p>
</li>
<li><p>TreeSet
&#x5E95;&#x5C42;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x662F;&#x7EA2;&#x9ED1;&#x6811;&#x3002;(&#x552F;&#x4E00;&#xFF0C;&#x6709;&#x5E8F;)</p>
</li>
<li><ol>
<li>&#x5982;&#x4F55;&#x4FDD;&#x8BC1;&#x5143;&#x7D20;&#x6392;&#x5E8F;&#x7684;&#x5462;?
&#x81EA;&#x7136;&#x6392;&#x5E8F;
&#x6BD4;&#x8F83;&#x5668;&#x6392;&#x5E8F;
2.&#x5982;&#x4F55;&#x4FDD;&#x8BC1;&#x5143;&#x7D20;&#x552F;&#x4E00;&#x6027;&#x7684;&#x5462;?
&#x6839;&#x636E;&#x6BD4;&#x8F83;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x5426;&#x662F;0&#x6765;&#x51B3;&#x5B9A;</li>
</ol>
</li>
</ul>
<p><strong>&#x9488;&#x5BF9;Collection&#x96C6;&#x5408;&#x6211;&#x4EEC;&#x5230;&#x5E95;&#x4F7F;&#x7528;&#x8C01;&#x5462;?(&#x638C;&#x63E1;)</strong></p>
<blockquote>
<p>&#x552F;&#x4E00;&#x5417;?</p>
<blockquote>
<p>&#x662F;&#xFF1A;Set</p>
<blockquote>
<p>&#x6392;&#x5E8F;&#x5417;?</p>
<blockquote>
<p>&#x662F;&#xFF1A;TreeSet&#x6216;LinkedHashSet
&#x5426;&#xFF1A;HashSet
&#x5982;&#x679C;&#x4F60;&#x77E5;&#x9053;&#x662F;Set&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x77E5;&#x9053;&#x662F;&#x54EA;&#x4E2A;Set&#xFF0C;&#x5C31;&#x7528;HashSet&#x3002;</p>
</blockquote>
</blockquote>
</blockquote>
<p>&#x5426;&#xFF1A;List</p>
<blockquote>
<p>&#x8981;&#x5B89;&#x5168;&#x5417;?</p>
<blockquote>
<p>&#x662F;&#xFF1A;Vector
&#x5426;&#xFF1A;ArrayList&#x6216;&#x8005;LinkedList</p>
<blockquote>
<p>&#x67E5;&#x8BE2;&#x591A;&#xFF1A;ArrayList
&#x589E;&#x5220;&#x591A;&#xFF1A;LinkedList
&#x5982;&#x679C;&#x4F60;&#x77E5;&#x9053;&#x662F;List&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x77E5;&#x9053;&#x662F;&#x54EA;&#x4E2A;List&#xFF0C;&#x5C31;&#x7528;ArrayList&#x3002;</p>
</blockquote>
</blockquote>
</blockquote>
<p>&#x5982;&#x679C;&#x4F60;&#x77E5;&#x9053;&#x662F;Collection&#x96C6;&#x5408;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x77E5;&#x9053;&#x4F7F;&#x7528;&#x8C01;&#xFF0C;&#x5C31;&#x7528;ArrayList&#x3002;
&#x5982;&#x679C;&#x4F60;&#x77E5;&#x9053;&#x7528;&#x96C6;&#x5408;&#xFF0C;&#x5C31;&#x7528;ArrayList&#x3002;</p>
</blockquote>
<p>&#x8BF4;&#x5B8C;&#x4E86;Collection,&#x6765;&#x7B80;&#x5355;&#x8BF4;&#x4E00;&#x4E0B;Map.</p>
<h3 id="map&#x63A5;&#x53E3;"><a name="map&#x63A5;&#x53E3;" class="anchor-navigation-ex-anchor" href="#map&#x63A5;&#x53E3;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="map&#x63A5;&#x53E3;" class="plugin-anchor" href="#map&#x63A5;&#x53E3;"><i class="fa fa-link" aria-hidden="true"></i></a>Map&#x63A5;&#x53E3;:</h3>
<p>&#x4E0A;&#x56FE;:
<img src="https://gitee.com/zisuu/picture/raw/master/img/20201221160920.png" alt="image-20201221160920253"></p>
<p>Map&#x63A5;&#x53E3;&#x6709;&#x4E09;&#x4E2A;&#x6BD4;&#x8F83;&#x91CD;&#x8981;&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x5206;&#x522B;&#x662F;HashMap&#x3001;TreeMap&#x548C;HashTable&#x3002;</p>
<ul>
<li>TreeMap&#x662F;&#x6709;&#x5E8F;&#x7684;&#xFF0C;HashMap&#x548C;HashTable&#x662F;&#x65E0;&#x5E8F;&#x7684;&#x3002;</li>
<li>Hashtable&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x540C;&#x6B65;&#x7684;&#xFF0C;HashMap&#x7684;&#x65B9;&#x6CD5;&#x4E0D;&#x662F;&#x540C;&#x6B65;&#x7684;&#x3002;&#x8FD9;&#x662F;&#x4E24;&#x8005;&#x6700;&#x4E3B;&#x8981;&#x7684;&#x533A;&#x522B;&#x3002;</li>
</ul>
<p>&#x8FD9;&#x5C31;&#x610F;&#x5473;&#x7740;:</p>
<ul>
<li>Hashtable&#x662F;&#x7EBF;&#x7A0B;&#x5B89;&#x5168;&#x7684;&#xFF0C;HashMap&#x4E0D;&#x662F;&#x7EBF;&#x7A0B;&#x5B89;&#x5168;&#x7684;&#x3002;</li>
<li>HashMap&#x6548;&#x7387;&#x8F83;&#x9AD8;&#xFF0C;Hashtable&#x6548;&#x7387;&#x8F83;&#x4F4E;&#x3002;
&#x5982;&#x679C;&#x5BF9;&#x540C;&#x6B65;&#x6027;&#x6216;&#x4E0E;&#x9057;&#x7559;&#x4EE3;&#x7801;&#x7684;&#x517C;&#x5BB9;&#x6027;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x8981;&#x6C42;&#xFF0C;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;HashMap&#x3002; &#x67E5;&#x770B;Hashtable&#x7684;&#x6E90;&#x4EE3;&#x7801;&#x5C31;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#xFF0C;&#x9664;&#x6784;&#x9020;&#x51FD;&#x6570;&#x5916;&#xFF0C;Hashtable&#x7684;&#x6240;&#x6709; public &#x65B9;&#x6CD5;&#x58F0;&#x660E;&#x4E2D;&#x90FD;&#x6709; synchronized&#x5173;&#x952E;&#x5B57;&#xFF0C;&#x800C;HashMap&#x7684;&#x6E90;&#x7801;&#x4E2D;&#x5219;&#x6CA1;&#x6709;&#x3002;</li>
<li>Hashtable&#x4E0D;&#x5141;&#x8BB8;null&#x503C;&#xFF0C;HashMap&#x5141;&#x8BB8;null&#x503C;&#xFF08;key&#x548C;value&#x90FD;&#x5141;&#x8BB8;&#xFF09;</li>
<li>&#x7236;&#x7C7B;&#x4E0D;&#x540C;&#xFF1A;Hashtable&#x7684;&#x7236;&#x7C7B;&#x662F;Dictionary&#xFF0C;HashMap&#x7684;&#x7236;&#x7C7B;&#x662F;AbstractMap</li>
</ul>
<h2 id="&#x91CD;&#x70B9;&#x95EE;&#x9898;&#x91CD;&#x70B9;&#x5206;&#x6790;"><a name="&#x91CD;&#x70B9;&#x95EE;&#x9898;&#x91CD;&#x70B9;&#x5206;&#x6790;" class="anchor-navigation-ex-anchor" href="#&#x91CD;&#x70B9;&#x95EE;&#x9898;&#x91CD;&#x70B9;&#x5206;&#x6790;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x91CD;&#x70B9;&#x95EE;&#x9898;&#x91CD;&#x70B9;&#x5206;&#x6790;" class="plugin-anchor" href="#&#x91CD;&#x70B9;&#x95EE;&#x9898;&#x91CD;&#x70B9;&#x5206;&#x6790;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x91CD;&#x70B9;&#x95EE;&#x9898;&#x91CD;&#x70B9;&#x5206;&#x6790;:</h2>
<h3 id="&#x4E00;treeset-linkedhashset-and-hashset-&#x7684;&#x533A;&#x522B;"><a name="&#x4E00;treeset-linkedhashset-and-hashset-&#x7684;&#x533A;&#x522B;" class="anchor-navigation-ex-anchor" href="#&#x4E00;treeset-linkedhashset-and-hashset-&#x7684;&#x533A;&#x522B;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4E00;treeset-linkedhashset-and-hashset-&#x7684;&#x533A;&#x522B;" class="plugin-anchor" href="#&#x4E00;treeset-linkedhashset-and-hashset-&#x7684;&#x533A;&#x522B;"><i class="fa fa-link" aria-hidden="true"></i></a>(&#x4E00;).TreeSet, LinkedHashSet and HashSet &#x7684;&#x533A;&#x522B;</h3>
<blockquote>
<p><strong>1. &#x4ECB;&#x7ECD;</strong></p>
<ul>
<li>TreeSet, LinkedHashSet and HashSet &#x5728;java&#x4E2D;&#x90FD;&#x662F;&#x5B9E;&#x73B0;Set&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;</li>
</ul>
</blockquote>
<ul>
<li>TreeSet&#x7684;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x7528;&#x4E8E;&#x6392;&#x5E8F;</li>
<li>LinkedHashSet&#x7684;&#x4E3B;&#x8981;&#x529F;&#x80FD;&#x7528;&#x4E8E;&#x4FDD;&#x8BC1;FIFO&#x5373;&#x6709;&#x5E8F;&#x7684;&#x96C6;&#x5408;(&#x5148;&#x8FDB;&#x5148;&#x51FA;)</li>
<li>HashSet&#x53EA;&#x662F;&#x901A;&#x7528;&#x7684;&#x5B58;&#x50A8;&#x6570;&#x636E;&#x7684;&#x96C6;&#x5408;</li>
</ul>
<blockquote>
<p><strong>2. &#x76F8;&#x540C;&#x70B9;</strong></p>
<ul>
<li>Duplicates elements: &#x56E0;&#x4E3A;&#x4E09;&#x8005;&#x90FD;&#x5B9E;&#x73B0;Set interface&#xFF0C;&#x6240;&#x4EE5;&#x4E09;&#x8005;&#x90FD;&#x4E0D;&#x5305;&#x542B;duplicate elements</li>
<li>Thread safety: &#x4E09;&#x8005;&#x90FD;&#x4E0D;&#x662F;&#x7EBF;&#x7A0B;&#x5B89;&#x5168;&#x7684;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x4F7F;&#x7528;&#x7EBF;&#x7A0B;&#x5B89;&#x5168;&#x53EF;&#x4EE5;Collections.synchronizedSet()</li>
</ul>
<p><strong>3. &#x4E0D;&#x540C;&#x70B9;</strong></p>
<ul>
<li>Performance and Speed: HashSet&#x63D2;&#x5165;&#x6570;&#x636E;&#x6700;&#x5FEB;&#xFF0C;&#x5176;&#x6B21;LinkHashSet&#xFF0C;&#x6700;&#x6162;&#x7684;&#x662F;TreeSet&#x56E0;&#x4E3A;&#x5185;&#x90E8;&#x5B9E;&#x73B0;&#x6392;&#x5E8F;</li>
</ul>
</blockquote>
<ul>
<li>Ordering: HashSet&#x4E0D;&#x4FDD;&#x8BC1;&#x6709;&#x5E8F;&#xFF0C;LinkHashSet&#x4FDD;&#x8BC1;FIFO&#x5373;&#x6309;&#x63D2;&#x5165;&#x987A;&#x5E8F;&#x6392;&#x5E8F;&#xFF0C;<strong>TreeSet&#x5B89;&#x88C5;&#x5185;&#x90E8;&#x5B9E;&#x73B0;&#x6392;&#x5E8F;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x6392;&#x5E8F;&#x89C4;&#x5219;</strong></li>
<li>null:HashSet&#x548C;LinkHashSet&#x5141;&#x8BB8;&#x5B58;&#x5728;null&#x6570;&#x636E;&#xFF0C;&#x4F46;&#x662F;TreeSet&#x4E2D;&#x63D2;&#x5165;null&#x6570;&#x636E;&#x65F6;&#x4F1A;&#x62A5;NullPointerException</li>
</ul>
<blockquote>
<p><strong>4. &#x4EE3;&#x7801;&#x6BD4;&#x8F83;</strong></p>
</blockquote>
<pre><code class="lang-java">  <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String args[])</span> </span>{
        HashSet&lt;String&gt; hashSet = <span class="hljs-keyword">new</span> HashSet&lt;&gt;();
        LinkedHashSet&lt;String&gt; linkedHashSet = <span class="hljs-keyword">new</span> LinkedHashSet&lt;&gt;();
        TreeSet&lt;String&gt; treeSet = <span class="hljs-keyword">new</span> TreeSet&lt;&gt;();

        <span class="hljs-keyword">for</span> (String data : Arrays.asList(<span class="hljs-string">&quot;B&quot;</span>, <span class="hljs-string">&quot;E&quot;</span>, <span class="hljs-string">&quot;D&quot;</span>, <span class="hljs-string">&quot;C&quot;</span>, <span class="hljs-string">&quot;A&quot;</span>)) {
            hashSet.add(data);
            linkedHashSet.add(data);
            treeSet.add(data);
        }

        <span class="hljs-comment">//&#x4E0D;&#x4FDD;&#x8BC1;&#x6709;&#x5E8F;</span>
        System.out.println(<span class="hljs-string">&quot;Ordering in HashSet :&quot;</span> + hashSet);

        <span class="hljs-comment">//FIFO&#x4FDD;&#x8BC1;&#x5B89;&#x88C5;&#x63D2;&#x5165;&#x987A;&#x5E8F;&#x6392;&#x5E8F;</span>
        System.out.println(<span class="hljs-string">&quot;Order of element in LinkedHashSet :&quot;</span> + linkedHashSet);

        <span class="hljs-comment">//&#x5185;&#x90E8;&#x5B9E;&#x73B0;&#x6392;&#x5E8F;</span>
        System.out.println(<span class="hljs-string">&quot;Order of objects in TreeSet :&quot;</span> + treeSet);


    }
<span class="hljs-number">12345678910111213141516171819202122</span>
</code></pre>
<blockquote>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;:
Ordering in HashSet :[A, B, C, D, E] (&#x65E0;&#x987A;&#x5E8F;)
Order of element in LinkedHashSet :[B, E, D, C, A] (FIFO&#x63D2;&#x5165;&#x6709;&#x5E8F;)
Order of objects in TreeSet :[A, B, C, D, E] (&#x6392;&#x5E8F;)</p>
</blockquote>
<h3 id="&#x4E8C;treeset&#x7684;&#x4E24;&#x79CD;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;"><a name="&#x4E8C;treeset&#x7684;&#x4E24;&#x79CD;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;" class="anchor-navigation-ex-anchor" href="#&#x4E8C;treeset&#x7684;&#x4E24;&#x79CD;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4E8C;treeset&#x7684;&#x4E24;&#x79CD;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;" class="plugin-anchor" href="#&#x4E8C;treeset&#x7684;&#x4E24;&#x79CD;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;"><i class="fa fa-link" aria-hidden="true"></i></a>(&#x4E8C;).TreeSet&#x7684;&#x4E24;&#x79CD;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;</h3>
<h5 id="1&#x6392;&#x5E8F;&#x7684;&#x5F15;&#x5165;&#x4EE5;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x6392;&#x5E8F;&#x4E3A;&#x4F8B;"><a name="1&#x6392;&#x5E8F;&#x7684;&#x5F15;&#x5165;&#x4EE5;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x6392;&#x5E8F;&#x4E3A;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#1&#x6392;&#x5E8F;&#x7684;&#x5F15;&#x5165;&#x4EE5;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x6392;&#x5E8F;&#x4E3A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="1&#x6392;&#x5E8F;&#x7684;&#x5F15;&#x5165;&#x4EE5;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x6392;&#x5E8F;&#x4E3A;&#x4F8B;" class="plugin-anchor" href="#1&#x6392;&#x5E8F;&#x7684;&#x5F15;&#x5165;&#x4EE5;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x6392;&#x5E8F;&#x4E3A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>1.&#x6392;&#x5E8F;&#x7684;&#x5F15;&#x5165;(&#x4EE5;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x6392;&#x5E8F;&#x4E3A;&#x4F8B;)</h5>
<p>&#x7531;&#x4E8E;TreeSet&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x5BF9;&#x5143;&#x7D20;&#x6309;&#x7167;&#x67D0;&#x79CD;&#x89C4;&#x5219;&#x8FDB;&#x884C;&#x6392;&#x5E8F;&#xFF0C;&#x4F8B;&#x5982;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-comment">// &#x521B;&#x5EFA;&#x96C6;&#x5408;&#x5BF9;&#x8C61;</span>
        <span class="hljs-comment">// &#x81EA;&#x7136;&#x987A;&#x5E8F;&#x8FDB;&#x884C;&#x6392;&#x5E8F;</span>
        TreeSet&lt;Integer&gt; ts = <span class="hljs-keyword">new</span> TreeSet&lt;Integer&gt;();

        <span class="hljs-comment">// &#x521B;&#x5EFA;&#x5143;&#x7D20;&#x5E76;&#x6DFB;&#x52A0;</span>
        <span class="hljs-comment">// 20,18,23,22,17,24,19,18,24</span>
        ts.add(<span class="hljs-number">20</span>);
        ts.add(<span class="hljs-number">18</span>);
        ts.add(<span class="hljs-number">23</span>);
        ts.add(<span class="hljs-number">22</span>);
        ts.add(<span class="hljs-number">17</span>);
        ts.add(<span class="hljs-number">24</span>);
        ts.add(<span class="hljs-number">19</span>);
        ts.add(<span class="hljs-number">18</span>);
        ts.add(<span class="hljs-number">24</span>);

        <span class="hljs-comment">// &#x904D;&#x5386;</span>
        <span class="hljs-keyword">for</span> (Integer i : ts) {
            System.out.println(i);
        }
    }
}
</code></pre>
<blockquote>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;:
17
18
19
20
22
23
24</p>
</blockquote>
<h5 id="2&#x5982;&#x679C;&#x662F;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5462;&#x6BD4;&#x5982;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x53C8;&#x8BE5;&#x5982;&#x4F55;&#x6392;&#x5E8F;&#x5462;"><a name="2&#x5982;&#x679C;&#x662F;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5462;&#x6BD4;&#x5982;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x53C8;&#x8BE5;&#x5982;&#x4F55;&#x6392;&#x5E8F;&#x5462;" class="anchor-navigation-ex-anchor" href="#2&#x5982;&#x679C;&#x662F;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5462;&#x6BD4;&#x5982;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x53C8;&#x8BE5;&#x5982;&#x4F55;&#x6392;&#x5E8F;&#x5462;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="2&#x5982;&#x679C;&#x662F;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5462;&#x6BD4;&#x5982;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x53C8;&#x8BE5;&#x5982;&#x4F55;&#x6392;&#x5E8F;&#x5462;" class="plugin-anchor" href="#2&#x5982;&#x679C;&#x662F;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5462;&#x6BD4;&#x5982;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x53C8;&#x8BE5;&#x5982;&#x4F55;&#x6392;&#x5E8F;&#x5462;"><i class="fa fa-link" aria-hidden="true"></i></a>2.&#x5982;&#x679C;&#x662F;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5462;,&#x6BD4;&#x5982;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;,&#x53C8;&#x8BE5;&#x5982;&#x4F55;&#x6392;&#x5E8F;&#x5462;?</h5>
<p>&#x6D4B;&#x8BD5;&#x7C7B;:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        TreeSet&lt;Student&gt; ts=<span class="hljs-keyword">new</span> TreeSet&lt;Student&gt;();
        <span class="hljs-comment">//&#x521B;&#x5EFA;&#x5143;&#x7D20;&#x5BF9;&#x8C61;</span>
        Student s1=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;zhangsan&quot;</span>,<span class="hljs-number">20</span>);
        Student s2=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;lis&quot;</span>,<span class="hljs-number">22</span>);
        Student s3=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;wangwu&quot;</span>,<span class="hljs-number">24</span>);
        Student s4=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;chenliu&quot;</span>,<span class="hljs-number">26</span>);
        Student s5=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;zhangsan&quot;</span>,<span class="hljs-number">22</span>);
        Student s6=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;qianqi&quot;</span>,<span class="hljs-number">24</span>);

        <span class="hljs-comment">//&#x5C06;&#x5143;&#x7D20;&#x5BF9;&#x8C61;&#x6DFB;&#x52A0;&#x5230;&#x96C6;&#x5408;&#x5BF9;&#x8C61;&#x4E2D;</span>
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);
        ts.add(s5);
        ts.add(s6);

        <span class="hljs-comment">//&#x904D;&#x5386;</span>
        <span class="hljs-keyword">for</span>(Student s:ts){
            System.out.println(s.getName()+<span class="hljs-string">&quot;-----------&quot;</span>+s.getAge());
        }
    }
}
</code></pre>
<p>Student.java:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span> </span>{
    <span class="hljs-keyword">private</span> String name;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> age;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Student</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">super</span>();
        <span class="hljs-comment">// TODO Auto-generated constructor stub</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Student</span><span class="hljs-params">(String name, <span class="hljs-keyword">int</span> age)</span> </span>{
        <span class="hljs-keyword">super</span>();
        <span class="hljs-keyword">this</span>.name = name;
        <span class="hljs-keyword">this</span>.age = age;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getName</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> name;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setName</span><span class="hljs-params">(String name)</span> </span>{
        <span class="hljs-keyword">this</span>.name = name;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getAge</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> age;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setAge</span><span class="hljs-params">(<span class="hljs-keyword">int</span> age)</span> </span>{
        <span class="hljs-keyword">this</span>.age = age;
    }
}

<span class="hljs-number">1234567891011121314151617181920212223242526272829303132</span>
</code></pre>
<p>&#x7ED3;&#x679C;&#x62A5;&#x9519;:</p>
<blockquote>
<p><img src="https://gitee.com/zisuu/picture/raw/master/img/20201221160930.png" alt="&#x8FD9;&#x91CC;&#x5199;&#x56FE;&#x7247;&#x63CF;&#x8FF0;">
&#x539F;&#x56E0;&#x5206;&#x6790;&#xFF1A;
&#x7531;&#x4E8E;&#x4E0D;&#x77E5;&#x9053;&#x8BE5;&#x5B89;&#x7167;&#x90A3;&#x4E00;&#x4E2D;&#x6392;&#x5E8F;&#x65B9;&#x5F0F;&#x6392;&#x5E8F;&#xFF0C;&#x6240;&#x4EE5;&#x4F1A;&#x62A5;&#x9519;&#x3002;
&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#xFF1A;
1.&#x81EA;&#x7136;&#x6392;&#x5E8F;
2.&#x6BD4;&#x8F83;&#x5668;&#x6392;&#x5E8F;</p>
</blockquote>
<h6 id="1&#x81EA;&#x7136;&#x6392;&#x5E8F;"><a name="1&#x81EA;&#x7136;&#x6392;&#x5E8F;" class="anchor-navigation-ex-anchor" href="#1&#x81EA;&#x7136;&#x6392;&#x5E8F;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="1&#x81EA;&#x7136;&#x6392;&#x5E8F;" class="plugin-anchor" href="#1&#x81EA;&#x7136;&#x6392;&#x5E8F;"><i class="fa fa-link" aria-hidden="true"></i></a>(1).&#x81EA;&#x7136;&#x6392;&#x5E8F;</h6>
<p>&#x81EA;&#x7136;&#x6392;&#x5E8F;&#x8981;&#x8FDB;&#x884C;&#x4E00;&#x4E0B;&#x64CD;&#x4F5C;&#xFF1A;
1.Student&#x7C7B;&#x4E2D;&#x5B9E;&#x73B0; Comparable&#x63A5;&#x53E3;
2.&#x91CD;&#x5199;Comparable&#x63A5;&#x53E3;&#x4E2D;&#x7684;Compareto&#x65B9;&#x6CD5;</p>
<pre><code class="lang-java">compareTo(T o)  &#x6BD4;&#x8F83;&#x6B64;&#x5BF9;&#x8C61;&#x4E0E;&#x6307;&#x5B9A;&#x5BF9;&#x8C61;&#x7684;&#x987A;&#x5E8F;&#x3002;
<span class="hljs-number">1</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Comparable</span>&lt;<span class="hljs-title">Student</span>&gt;</span>{
    <span class="hljs-keyword">private</span> String name;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> age;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Student</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">super</span>();
        <span class="hljs-comment">// TODO Auto-generated constructor stub</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Student</span><span class="hljs-params">(String name, <span class="hljs-keyword">int</span> age)</span> </span>{
        <span class="hljs-keyword">super</span>();
        <span class="hljs-keyword">this</span>.name = name;
        <span class="hljs-keyword">this</span>.age = age;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getName</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> name;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setName</span><span class="hljs-params">(String name)</span> </span>{
        <span class="hljs-keyword">this</span>.name = name;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getAge</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> age;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setAge</span><span class="hljs-params">(<span class="hljs-keyword">int</span> age)</span> </span>{
        <span class="hljs-keyword">this</span>.age = age;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">compareTo</span><span class="hljs-params">(Student s)</span> </span>{
        <span class="hljs-comment">//return -1; //-1&#x8868;&#x793A;&#x653E;&#x5728;&#x7EA2;&#x9ED1;&#x6811;&#x7684;&#x5DE6;&#x8FB9;,&#x5373;&#x9006;&#x5E8F;&#x8F93;&#x51FA;</span>
        <span class="hljs-comment">//return 1;  //1&#x8868;&#x793A;&#x653E;&#x5728;&#x7EA2;&#x9ED1;&#x6811;&#x7684;&#x53F3;&#x8FB9;&#xFF0C;&#x5373;&#x987A;&#x5E8F;&#x8F93;&#x51FA;</span>
        <span class="hljs-comment">//return o;  //&#x8868;&#x793A;&#x5143;&#x7D20;&#x76F8;&#x540C;&#xFF0C;&#x4EC5;&#x5B58;&#x653E;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</span>
        <span class="hljs-comment">//&#x4E3B;&#x8981;&#x6761;&#x4EF6; &#x59D3;&#x540D;&#x7684;&#x957F;&#x5EA6;,&#x5982;&#x679C;&#x59D3;&#x540D;&#x957F;&#x5EA6;&#x5C0F;&#x7684;&#x5C31;&#x653E;&#x5728;&#x5DE6;&#x5B50;&#x6811;&#xFF0C;&#x5426;&#x5219;&#x653E;&#x5728;&#x53F3;&#x5B50;&#x6811;</span>
        <span class="hljs-keyword">int</span> num=<span class="hljs-keyword">this</span>.name.length()-s.name.length();
        <span class="hljs-comment">//&#x59D3;&#x540D;&#x7684;&#x957F;&#x5EA6;&#x76F8;&#x540C;&#xFF0C;&#x4E0D;&#x4EE3;&#x8868;&#x5185;&#x5BB9;&#x76F8;&#x540C;,&#x5982;&#x679C;&#x6309;&#x5B57;&#x5178;&#x987A;&#x5E8F;&#x6B64; String &#x5BF9;&#x8C61;&#x4F4D;&#x4E8E;&#x53C2;&#x6570;&#x5B57;&#x7B26;&#x4E32;&#x4E4B;&#x524D;&#xFF0C;&#x5219;&#x6BD4;&#x8F83;&#x7ED3;&#x679C;&#x4E3A;&#x4E00;&#x4E2A;&#x8D1F;&#x6574;&#x6570;&#x3002;</span>
        <span class="hljs-comment">//&#x5982;&#x679C;&#x6309;&#x5B57;&#x5178;&#x987A;&#x5E8F;&#x6B64; String &#x5BF9;&#x8C61;&#x4F4D;&#x4E8E;&#x53C2;&#x6570;&#x5B57;&#x7B26;&#x4E32;&#x4E4B;&#x540E;&#xFF0C;&#x5219;&#x6BD4;&#x8F83;&#x7ED3;&#x679C;&#x4E3A;&#x4E00;&#x4E2A;&#x6B63;&#x6574;&#x6570;&#x3002;</span>
        <span class="hljs-comment">//&#x5982;&#x679C;&#x8FD9;&#x4E24;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x76F8;&#x7B49;&#xFF0C;&#x5219;&#x7ED3;&#x679C;&#x4E3A; 0</span>
        <span class="hljs-keyword">int</span> num1=num==<span class="hljs-number">0</span>?<span class="hljs-keyword">this</span>.name.compareTo(s.name):num;
        <span class="hljs-comment">//&#x59D3;&#x540D;&#x7684;&#x957F;&#x5EA6;&#x548C;&#x5185;&#x5BB9;&#x76F8;&#x540C;&#xFF0C;&#x4E0D;&#x4EE3;&#x8868;&#x5E74;&#x9F84;&#x76F8;&#x540C;&#xFF0C;&#x6240;&#x4EE5;&#x8FD8;&#x8981;&#x5224;&#x65AD;&#x5E74;&#x9F84;</span>
        <span class="hljs-keyword">int</span> num2=num1==<span class="hljs-number">0</span>?<span class="hljs-keyword">this</span>.age-s.age:num1;
        <span class="hljs-keyword">return</span> num2;
    }
}

<span class="hljs-number">123456789101112131415161718192021222324252627282930313233343536373839404142434445464748</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;:</p>
<blockquote>
<p>lis-----------22
qianqi-----------24
wangwu-----------24
chenliu-----------26
zhangsan-----------20
zhangsan-----------22</p>
</blockquote>
<h6 id="2&#x6BD4;&#x8F83;&#x5668;&#x6392;&#x5E8F;"><a name="2&#x6BD4;&#x8F83;&#x5668;&#x6392;&#x5E8F;" class="anchor-navigation-ex-anchor" href="#2&#x6BD4;&#x8F83;&#x5668;&#x6392;&#x5E8F;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="2&#x6BD4;&#x8F83;&#x5668;&#x6392;&#x5E8F;" class="plugin-anchor" href="#2&#x6BD4;&#x8F83;&#x5668;&#x6392;&#x5E8F;"><i class="fa fa-link" aria-hidden="true"></i></a>(2).&#x6BD4;&#x8F83;&#x5668;&#x6392;&#x5E8F;</h6>
<p>&#x6BD4;&#x8F83;&#x5668;&#x6392;&#x5E8F;&#x6B65;&#x9AA4;&#xFF1A;
1.&#x5355;&#x72EC;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x7C7B;&#xFF0C;&#x8FD9;&#x91CC;&#x4EE5;MyComparator&#x4E3A;&#x4F8B;&#xFF0C;&#x5E76;&#x4E14;&#x8981;&#x8BA9;&#x5176;&#x7EE7;&#x627F;Comparator&#x63A5;&#x53E3;
2.&#x91CD;&#x5199;Comparator&#x63A5;&#x53E3;&#x4E2D;&#x7684;Compare&#x65B9;&#x6CD5;</p>
<pre><code class="lang-java">compare(T o1,T o2)      &#x6BD4;&#x8F83;&#x7528;&#x6765;&#x6392;&#x5E8F;&#x7684;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x3002;
<span class="hljs-number">1</span>
</code></pre>
<p>3.&#x5728;&#x4E3B;&#x7C7B;&#x4E2D;&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x7684; &#x6784;&#x9020;&#x65B9;&#x6CD5;</p>
<pre><code class="lang-java">TreeSet(Comparator&lt;? superE&gt; comparator)
          &#x6784;&#x9020;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x7A7A; TreeSet&#xFF0C;&#x5B83;&#x6839;&#x636E;&#x6307;&#x5B9A;&#x6BD4;&#x8F83;&#x5668;&#x8FDB;&#x884C;&#x6392;&#x5E8F;&#x3002;
<span class="hljs-number">12</span>
</code></pre>
<p>&#x6D4B;&#x8BD5;&#x7C7B;:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        <span class="hljs-comment">//&#x521B;&#x5EFA;&#x96C6;&#x5408;&#x5BF9;&#x8C61;</span>
        <span class="hljs-comment">//TreeSet(Comparator&lt;? super E&gt; comparator) &#x6784;&#x9020;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x7A7A; TreeSet&#xFF0C;&#x5B83;&#x6839;&#x636E;&#x6307;&#x5B9A;&#x6BD4;&#x8F83;&#x5668;&#x8FDB;&#x884C;&#x6392;&#x5E8F;&#x3002;</span>
        TreeSet&lt;Student&gt; ts=<span class="hljs-keyword">new</span> TreeSet&lt;Student&gt;(<span class="hljs-keyword">new</span> MyComparator());

        <span class="hljs-comment">//&#x521B;&#x5EFA;&#x5143;&#x7D20;&#x5BF9;&#x8C61;</span>
        Student s1=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;zhangsan&quot;</span>,<span class="hljs-number">20</span>);
        Student s2=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;lis&quot;</span>,<span class="hljs-number">22</span>);
        Student s3=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;wangwu&quot;</span>,<span class="hljs-number">24</span>);
        Student s4=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;chenliu&quot;</span>,<span class="hljs-number">26</span>);
        Student s5=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;zhangsan&quot;</span>,<span class="hljs-number">22</span>);
        Student s6=<span class="hljs-keyword">new</span> Student(<span class="hljs-string">&quot;qianqi&quot;</span>,<span class="hljs-number">24</span>);

        <span class="hljs-comment">//&#x5C06;&#x5143;&#x7D20;&#x5BF9;&#x8C61;&#x6DFB;&#x52A0;&#x5230;&#x96C6;&#x5408;&#x5BF9;&#x8C61;&#x4E2D;</span>
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);
        ts.add(s5);
        ts.add(s6);

        <span class="hljs-comment">//&#x904D;&#x5386;</span>
        <span class="hljs-keyword">for</span>(Student s:ts){
            System.out.println(s.getName()+<span class="hljs-string">&quot;-----------&quot;</span>+s.getAge());
        }
    }
}

<span class="hljs-number">123456789101112131415161718192021222324252627282930</span>
</code></pre>
<p>Student.java:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span> </span>{
    <span class="hljs-keyword">private</span> String name;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> age;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Student</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">super</span>();
        <span class="hljs-comment">// TODO Auto-generated constructor stub</span>
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Student</span><span class="hljs-params">(String name, <span class="hljs-keyword">int</span> age)</span> </span>{
        <span class="hljs-keyword">super</span>();
        <span class="hljs-keyword">this</span>.name = name;
        <span class="hljs-keyword">this</span>.age = age;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getName</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> name;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setName</span><span class="hljs-params">(String name)</span> </span>{
        <span class="hljs-keyword">this</span>.name = name;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getAge</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> age;
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setAge</span><span class="hljs-params">(<span class="hljs-keyword">int</span> age)</span> </span>{
        <span class="hljs-keyword">this</span>.age = age;
    }

}

<span class="hljs-number">123456789101112131415161718192021222324252627282930313233</span>
</code></pre>
<p>MyComparator&#x7C7B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyComparator</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Comparator</span>&lt;<span class="hljs-title">Student</span>&gt; </span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">compare</span><span class="hljs-params">(Student s1,Student s2)</span> </span>{
        <span class="hljs-comment">// &#x59D3;&#x540D;&#x957F;&#x5EA6;</span>
        <span class="hljs-keyword">int</span> num = s1.getName().length() - s2.getName().length();
        <span class="hljs-comment">// &#x59D3;&#x540D;&#x5185;&#x5BB9;</span>
        <span class="hljs-keyword">int</span> num2 = num == <span class="hljs-number">0</span> ? s1.getName().compareTo(s2.getName()) : num;
        <span class="hljs-comment">// &#x5E74;&#x9F84;</span>
        <span class="hljs-keyword">int</span> num3 = num2 == <span class="hljs-number">0</span> ? s1.getAge() - s2.getAge() : num2;
        <span class="hljs-keyword">return</span> num3;
    }

}
<span class="hljs-number">1234567891011121314</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;:</p>
<blockquote>
<p>lis-----------22
qianqi-----------24
wangwu-----------24
chenliu-----------26
zhangsan-----------20
zhangsan-----------22</p>
</blockquote>
<h3 id="&#x4E09;-&#x6027;&#x80FD;&#x6D4B;&#x8BD5;"><a name="&#x4E09;-&#x6027;&#x80FD;&#x6D4B;&#x8BD5;" class="anchor-navigation-ex-anchor" href="#&#x4E09;-&#x6027;&#x80FD;&#x6D4B;&#x8BD5;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4E09;-&#x6027;&#x80FD;&#x6D4B;&#x8BD5;" class="plugin-anchor" href="#&#x4E09;-&#x6027;&#x80FD;&#x6D4B;&#x8BD5;"><i class="fa fa-link" aria-hidden="true"></i></a>(&#x4E09;). &#x6027;&#x80FD;&#x6D4B;&#x8BD5;</h3>
<p>&#x5BF9;&#x8C61;&#x7C7B;:</p>
<pre><code class="lang-java"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Dog</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Comparable</span>&lt;<span class="hljs-title">Dog</span>&gt; </span>{
    <span class="hljs-keyword">int</span> size;
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Dog</span><span class="hljs-params">(<span class="hljs-keyword">int</span> s)</span> </span>{
        size = s;
    }
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">toString</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> size + <span class="hljs-string">&quot;&quot;</span>;
    }
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">compareTo</span><span class="hljs-params">(Dog o)</span> </span>{
       <span class="hljs-comment">//&#x6570;&#x503C;&#x5927;&#x5C0F;&#x6BD4;&#x8F83;</span>
        <span class="hljs-keyword">return</span> size - o.size;
    }
}
<span class="hljs-number">1234567891011121314</span>
</code></pre>
<p>&#x4E3B;&#x7C7B;:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        Random r = <span class="hljs-keyword">new</span> Random();
        HashSet&lt;Dog&gt; hashSet = <span class="hljs-keyword">new</span> HashSet&lt;Dog&gt;();
        TreeSet&lt;Dog&gt; treeSet = <span class="hljs-keyword">new</span> TreeSet&lt;Dog&gt;();
        LinkedHashSet&lt;Dog&gt; linkedSet = <span class="hljs-keyword">new</span> LinkedHashSet&lt;Dog&gt;();

        <span class="hljs-comment">// start time</span>
        <span class="hljs-keyword">long</span> startTime = System.nanoTime();
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">1000</span>; i++) {
            <span class="hljs-keyword">int</span> x = r.nextInt(<span class="hljs-number">1000</span> - <span class="hljs-number">10</span>) + <span class="hljs-number">10</span>;
            hashSet.add(<span class="hljs-keyword">new</span> Dog(x));
        }

        <span class="hljs-comment">// end time</span>
        <span class="hljs-keyword">long</span> endTime = System.nanoTime();
        <span class="hljs-keyword">long</span> duration = endTime - startTime;
        System.out.println(<span class="hljs-string">&quot;HashSet: &quot;</span> + duration);

        <span class="hljs-comment">// start time</span>
        startTime = System.nanoTime();
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">1000</span>; i++) {
            <span class="hljs-keyword">int</span> x = r.nextInt(<span class="hljs-number">1000</span> - <span class="hljs-number">10</span>) + <span class="hljs-number">10</span>;
            treeSet.add(<span class="hljs-keyword">new</span> Dog(x));
        }
        <span class="hljs-comment">// end time</span>
        endTime = System.nanoTime();
        duration = endTime - startTime;
        System.out.println(<span class="hljs-string">&quot;TreeSet: &quot;</span> + duration);

        <span class="hljs-comment">// start time</span>
        startTime = System.nanoTime();
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">1000</span>; i++) {
            <span class="hljs-keyword">int</span> x = r.nextInt(<span class="hljs-number">1000</span> - <span class="hljs-number">10</span>) + <span class="hljs-number">10</span>;
            linkedSet.add(<span class="hljs-keyword">new</span> Dog(x));
        }

        <span class="hljs-comment">// end time</span>
        endTime = System.nanoTime();
        duration = endTime - startTime;
        System.out.println(<span class="hljs-string">&quot;LinkedHashSet: &quot;</span> + duration);
    }

}

<span class="hljs-number">1234567891011121314151617181920212223242526272829303132333435363738394041424344454647</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;:</p>
<blockquote>
<p>HashSet: 1544313
TreeSet: 2066049
LinkedHashSet: 629826
&#x867D;&#x7136;&#x6D4B;&#x8BD5;&#x4E0D;&#x591F;&#x51C6;&#x786E;,&#x4F46;&#x80FD;&#x53CD;&#x6620;&#x5F97;&#x51FA;&#xFF0C;TreeSet&#x8981;&#x6162;&#x5F97;&#x591A;,&#x56E0;&#x4E3A;&#x5B83;&#x662F;&#x6709;&#x5E8F;&#x7684;&#x3002;</p>
</blockquote>
<p><img src="https://gitee.com/zisuu/picture/raw/master/img/20201221160942.png" alt="image-20201221160942237"></p>

<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../../多线程/10面试题二.html" class="navigation navigation-prev " aria-label="Previous page: 13.面试题二.md">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="2.HashMap源码分析.html" class="navigation navigation-next " aria-label="Next page: 2.hashMap底层原理">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.集合架构","level":"7.1","depth":1,"next":{"title":"2.hashMap底层原理","level":"7.2","depth":1,"path":"basic/collection/2.HashMap源码分析.md","ref":"basic/collection/2.HashMap源码分析.md","articles":[]},"previous":{"title":"13.面试题二.md","level":"6.14","depth":1,"path":"多线程/10面试题二.md","ref":"多线程/10面试题二.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","splitter","expandable-chapters-small","anchors","sharing-plus","anchor-navigation-ex","favicon","expandable-chapters","toggle-chapters","back-to-top-button","code","-lunr","-search","search-pro","pageview-count","popup","livereload"],"styles":{"website":"./styles/website.css"},"pluginsConfig":{"livereload":{},"splitter":{},"search-pro":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"popup":{},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"favicon":{},"back-to-top-button":{},"pageview-count":{},"expandable-chapters-small":{},"sharing":{"qq":false,"all":["google","facebook","weibo","twitter","qq","qzone","linkedin","pocket"],"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{},"toggle-chapters":{},"expandable-chapters":{}},"theme":"default","author":"hzh","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"计算机 ,java , 大数据 基础知识体系","language":"zh-hans","gitbook":"3.2.3"},"file":{"path":"basic/collection/1.java集合.md","mtime":"2020-12-21T08:09:43.659Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-12-30T11:12:56.611Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

